//快速幂
//测试链接：https://leetcode.cn/problems/powx-n/
public class MyPow {
    public double myPow(double x, int n) {
        if(n < 0) return 1 / pow(x,-n);
        else return pow(x,n);
    }

    public double pow(double x, long n) {
        if(n == 0) return 1;
        double temp = pow(x,n/2);
        return n % 2 == 0 ? temp * temp : temp * temp * x;
    }
}
